package main

import (
	"io/ioutil"
	"log"
	"net/http"
	"sync"
)

var wg sync.WaitGroup
var urL="http://9.134.5.74:8083";

const num_coroutines=5;
const num_request_per_coroutine=2

func get_page(){
	/// 这里每一次 Get 都是short conn
	// https://stackoverflow.com/questions/39813587/go-client-program-generates-a-lot-a-sockets-in-time-wait-state/39834253#39834253
	response, err := http.Get(urL)
	if err != nil {
		log.Fatal(err)
	} else {
		defer response.Body.Close()
		_, err =ioutil.ReadAll(response.Body)
		if err != nil {
				log.Fatal(err)
		}
	}

}
func get_pages(){
	defer wg.Done()
	for i := 0; i < num_request_per_coroutine; i++{
		get_page();
	}
}

func tClientWithShortConnPerRequest() {
	for i:=0;i<num_coroutines;i++{
		wg.Add(1)
		go get_pages()
	}
	wg.Wait()
}